package cn.qg.biz.service.qggoods;
import cn.qg.beans.pojo.QgGoods;
import cn.qg.common.Constants;
import cn.qg.common.EmptyUtils;
import cn.qg.common.Page;
import cn.qg.mapper.qggoods.QgGoodsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class QgGoodsServiceImpl implements QgGoodsService {

    @Resource
    private QgGoodsMapper qgGoodsMapper;

    @Override
    public QgGoods getQgGoodsById(Long id)throws Exception{
        return qgGoodsMapper.getQgGoodsById(id);
    }

    @Override
    public List<QgGoods> getQgGoodsListByMap(Map<String,Object> param)throws Exception{
        return qgGoodsMapper.getQgGoodsListByMap(param);
    }

    @Override
    public Integer getQgGoodsCountByMap(Map<String,Object> param)throws Exception{
        return qgGoodsMapper.getQgGoodsCountByMap(param);
    }

    @Override
    public Integer qgtxAddQgGoods(QgGoods qgGoods)throws Exception{
            qgGoods.setCreatedTime(new Date());
            return qgGoodsMapper.insertQgGoods(qgGoods);
    }

    @Override
    public Integer qgtxModifyQgGoods(QgGoods qgGoods)throws Exception{
        qgGoods.setCreatedTime(new Date());
        return qgGoodsMapper.updateQgGoods(qgGoods);
    }

    @Override
    public Integer qgtxDeleteQgGoodsById(Long id)throws Exception{
        return qgGoodsMapper.deleteQgGoodsById(id);
    }

    @Override
    public Page<QgGoods> queryQgGoodsPageByMap(Map<String,Object> param,Integer pageNo,Integer pageSize)throws Exception{
        Integer total = qgGoodsMapper.getQgGoodsCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<QgGoods> qgGoodsList = qgGoodsMapper.getQgGoodsListByMap(param);
        page.setRows(qgGoodsList);
        return page;
    }

}
